package dialogos;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Hashtable;
import java.util.List;
import javax.swing.BorderFactory;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.LineBorder;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;

import datos.Cliente;
import datos.Profesional;

import accesoADatos.AccesoADatos;
import paneles.PanelClientes;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ModifClienteJDialog extends javax.swing.JDialog {
	private PanelClientes panelClientes1;
	private JPanel jPanel1;
	private JComboBox jComboBox1;
	private Hashtable hash;

	/**
	* Auto-generated main method to display this JDialog
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				ModifClienteJDialog inst = new ModifClienteJDialog(frame);
				inst.setVisible(true);
			}
		});
	}
	
	public ModifClienteJDialog(JFrame frame) {
		super(frame,"Modificar Cliente",true);
		hash=new Hashtable();
		initGUI();
	}
	
	private void initGUI() {
		try {
			{
				panelClientes1 = new PanelClientes();
				getContentPane().add(panelClientes1, BorderLayout.CENTER);
				panelClientes1.setPreferredSize(new java.awt.Dimension(308, 349));
				panelClientes1.getBCancelar().addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						bCancelarActionPerformed(evt);
					}
				});
				panelClientes1.getBAceptar().addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						bAceptarActionPerformed(evt);
					}
				});
			}
			{
				jPanel1 = new JPanel();
				FlowLayout jPanel1Layout = new FlowLayout();
				jPanel1Layout.setVgap(10);
				jPanel1.setLayout(jPanel1Layout);
				getContentPane().add(jPanel1, BorderLayout.NORTH);
				jPanel1.setPreferredSize(new java.awt.Dimension(307, 40));
				{
					List l=AccesoADatos.getInstance().getClientes();
				
					ComboBoxModel jComboBox1Model = 
						new DefaultComboBoxModel(
								l.toArray());
					for (int i=0; i<l.size(); i++)
						hash.put(l.get(i).toString(),l.get(i));
					jComboBox1 = new JComboBox();
					jPanel1.add(jComboBox1);
					jComboBox1.setModel(jComboBox1Model);
					Cliente c = (Cliente)hash.get(jComboBox1Model.getSelectedItem().toString());
					this.panelClientes1.cargarCliente(c);
					jComboBox1.setPreferredSize(new java.awt.Dimension(200, 21));
					jComboBox1.setBackground(new java.awt.Color(255,255,255));
					jComboBox1.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
					jComboBox1.addPopupMenuListener(new PopupMenuListener() {
						public void popupMenuWillBecomeVisible(PopupMenuEvent evt) {
							
						}
						public void popupMenuWillBecomeInvisible(PopupMenuEvent evt) {
							jComboBox1PopupMenuWillBecomeInvisible(evt);
						}
						public void popupMenuCanceled(PopupMenuEvent evt) {
							
						}
					});
				}
			}
			pack();
			this.setSize(330, 420);
			this.setLocationRelativeTo(null);
			this.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	private void jComboBox1PopupMenuWillBecomeInvisible(PopupMenuEvent evt) {
		Cliente c=(Cliente) hash.get(this.jComboBox1.getSelectedItem().toString());
		this.panelClientes1.cargarCliente(c);	
	}
	
	private void bAceptarActionPerformed(ActionEvent evt) {
		Cliente c=panelClientes1.getCliente();
		Cliente cl=(Cliente) this.hash.get(this.jComboBox1.getSelectedItem().toString());
		cl.setApellido(c.getApellido());
		cl.setCelular(c.getCelular());
		cl.setDireccion(c.getDireccion());
		cl.setEmail(c.getEmail());
		cl.setFoto(c.getFoto());
		cl.setNombre(c.getNombre());
		cl.setTelefono(c.getTelefono());
		AccesoADatos.getInstance().setObjeto(cl);
		this.dispose();
		
	}
	
	private void bCancelarActionPerformed(ActionEvent evt) {
		this.dispose();
	}

}
